//
//  SearchMessViewController.swift
//  SkylowAPP
//
//  Created by 漫云 on 2024/9/24.
//

import UIKit

class SearchMessViewController: UIViewController,UISearchBarDelegate {
    

    
    lazy var tableView: UITableView = UITableView(frame: CGRect.zero, style: .plain)
    override func viewDidLoad() {
        super.viewDidLoad()

        let searchBar = UISearchBar()
        searchBar.placeholder = "Search"
        searchBar.delegate = self as? UISearchBarDelegate
        searchBar.backgroundColor = .black
        //设置代理
        searchBar.delegate = self
        //设置搜索栏的颜色
        searchBar.barTintColor = UIColor.blue
        searchBar.tintColor = UIColor.white
        
        // 如果你想改变搜索框内的文本颜色
        if let textField = searchBar.value(forKey: "searchField") as? UITextField {
            textField.textColor = .white
        }
        

        self.navigationItem.titleView = searchBar
      
        self.view.backgroundColor = UIColor.colorWith(hexString: "#333333")
        tableView.backgroundColor = UIColor.colorWith(hexString: "#333333")
        tableView.tableFooterView = UIView()
        tableView.dataSource = self
        tableView.delegate = self
        let nibCell = UINib(nibName: "MessageItemCell", bundle: nil)
        tableView.register(nibCell, forCellReuseIdentifier: MessageItemCell.identifiers)
        view.addSubview(tableView)

    }
    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()

        tableView.frame = view.bounds
    }

    //当输入文字变化时调用的方法
    func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
        print(searchText)
    }
    
}
extension SearchMessViewController: UITableViewDataSource, UITableViewDelegate {
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 12
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: MessageItemCell.identifiers, for: indexPath) as! MessageItemCell
        return cell
    }

    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 100
    }

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let vc = AdvancedExampleViewController()
        navigationController?.pushViewController(vc, animated: true)
    }
}


